import { setLocalStorage } from '@/utils/localStorage'
const state = {
  hisActivedIndex: 1,
  patientInfo: {},
  depArea: '',
  selectedPatientInfo: {},
  filterPatientInfo: [],
  rowCurr: {},
  cardId: ''
}
const mutations = {
  SETCARDID(state, value) {
    state.cardId = value
  },
  SETROWCURR(state, info) {
    state.rowCurr = info
  },
  SETINFO(state, info) {
    state.patientInfo = info
  },
  SELECTEDPATIENTINFO(state, info) {
    state.selectedPatientInfo = info
  },
  setFilterPatientInfo(state, patInfo) {
    state.filterPatientInfo = []
    patInfo.forEach(element => {
      state.filterPatientInfo.push(element)
    })
  },
  SETHisActivedIndex(state, index) {
    state.hisActivedIndex = index
    setLocalStorage('hisActivedIndex', index)
  },
  SETDepArea(state, data) {
    state.depArea = data
  }
}
const actions = {
  setCardId({ commit }, value) {
    commit('SETCARDID', value)
  },
  setRowCurr({ commit }, info) {
    commit('SETROWCURR', info)
  },
  // 设置患者信息
  setInfo({ commit }, patInfo) {
    commit('SETINFO', patInfo)
  },
  // 设置所选中的患者信息，用于检查预约登记页面与已预约列表模块的联动
  setSelectedPatientInfo({ commit }, patInfo) {
    // // console.log('patInfo', patInfo)
    commit('SELECTEDPATIENTINFO', patInfo)
  },
  setFilterPatientInfo({ commit }, patInfos) {
    commit('setFilterPatientInfo', patInfos)
  },
  setHisActivedIndex({ commit }, index) {
    commit('SETHisActivedIndex', index)
  },
  setDepArea({ commit }, data) {
    commit('SETDepArea', data)
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
